package com.sn.author.controller;

import com.sn.author.common.annotation.Advice;
import com.sn.author.domain.BaseResult;
import com.sn.author.domain.dto.CollectionDTO;
import com.sn.author.domain.vo.*;
import com.sn.author.service.dao.CollectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author xiaom
 * @Date 2020/10/22 15:50
 * @Version 1.0.0
 * @Description <>
 **/
@RestController
@RequestMapping(value = "/collection")
@Api(tags = "采集")
public class CollectionController {

    @Autowired
    private CollectionService collectionService;

    @PostMapping(value = "/start")
    @ApiOperation("数据采集")
    public BaseResult<Boolean> collectionStart(@RequestBody NumberVo numberVo){
        return BaseResult.success(collectionService.collection(numberVo));
    }

    @PostMapping(value = "/list")
    @ApiOperation("获取采集历史记录")
    public BaseResult<List<CollectionDTO>> list(@RequestBody QueryTimeVo queryTimeVo){
        return collectionService.pageList(queryTimeVo);
    }

    @PostMapping(value = "/export")
    @ApiOperation("导出采集数据")
    public String export(@RequestBody TaskParamVo taskParamVo){
        collectionService.export(Long.parseLong(taskParamVo.getTaskId()));
        return "success";
    }

}
